package com.ceair.aiService.tools;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.lang.UUID;
import com.ceair.entity.OrderDemo;
import com.ceair.service.IOrderDemoService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author wangbaohai
 * @ClassName AirfreightAssistantTools
 * @description: 航空货运助手业务工具
 * @date 2025年05月21日
 * @version: 1.0.0
 */
@Component
@RequiredArgsConstructor
public class AirfreightAssistantTools {

    private final IOrderDemoService orderDemoService;

    @Tool(name = "createOrder", value = "请用户确认所有参数，如果参数缺失则提示补充，用户确认参数无误后，执行创建订单")
    public String createOrderDemo(@P(value = "收货人名称") String consignee,
                                  @P(value = "收货人联系方式") String consigneePhone,
                                  @P(value = "收货人邮箱") String consigneeEmail,
                                  @P(value = "收货人地址") String consigneeAddress,
                                  @P(value = "发货人名称") String consigner,
                                  @P(value = "发货人联系方式") String consignerPhone,
                                  @P(value = "发货人邮箱") String consignerEmail,
                                  @P(value = "发货人地址") String consignerAddress,
                                  @P(value = "货物描述") String goodsDescription,
                                  @P(value = "货物类型") String goodsType,
                                  @P(value = "包装类型") String packagingType,
                                  @P(value = "货物总重量") BigDecimal totalWeight,
                                  @P(value = "获取总件数") Integer totalPieces) {
        // 初始化
        OrderDemo orderDemo = new OrderDemo();

        // 设置插入数据
        orderDemo.setConsignee(consignee);
        orderDemo.setConsigneePhone(consigneePhone);
        orderDemo.setConsigneeEmail(consigneeEmail);
        orderDemo.setConsigneeAddress(consigneeAddress);
        orderDemo.setConsigner(consigner);
        orderDemo.setConsignerPhone(consignerPhone);
        orderDemo.setConsignerEmail(consignerEmail);
        orderDemo.setConsignerAddress(consignerAddress);
        orderDemo.setGoodsDescription(goodsDescription);
        orderDemo.setGoodsType(goodsType);
        orderDemo.setPackagingType(packagingType);
        orderDemo.setTotalWeight(totalWeight);
        orderDemo.setTotalPieces(totalPieces);

        // UUID 生成 orderNo
        orderDemo.setOrderNo(UUID.fastUUID().toString());

        // 保存
        orderDemoService.save(orderDemo);

        return "创建订单成功，订单号：" + orderDemo.getOrderNo();
    }

}
